from langchain.chat_models import ChatOpenAI
from langchain.prompts import ChatPromptTemplate

# 配置 DeepSeek AI
DEEPSEEK_API_KEY = "sk-079f9ad2ad3f457ebd6e6eb90f56fb53"  # 替换为您的实际API密钥
DEEPSEEK_API_BASE = "https://api.deepseek.com/v1"

# 创建 DeepSeek 聊天模型
chat = ChatOpenAI(
    temperature=0.0,
    model="deepseek-chat",  # DeepSeek 模型名称
    openai_api_key=DEEPSEEK_API_KEY,
    openai_api_base=DEEPSEEK_API_BASE
)

# 翻译模板
template_string = """Translate the text \
that is delimited by triple backticks \
into a style that is {style}. \
text: ```{text}```
"""

# 创建提示模板
prompt_template = ChatPromptTemplate.from_template(template_string)

# 第一部分：客户邮件翻译
customer_style = """American English in a calm and respectful tone"""
customer_email = """
Arrr, I be fuming that me blender lid \
flew off and splattered me kitchen walls \
with smoothie! And to make matters worse, \
the warranty don't cover the cost of \
cleaning up me kitchen. I need yer help \
right now, matey!
"""

# 格式化消息
customer_messages = prompt_template.format_messages(
    style=customer_style,
    text=customer_email
)

# 调用 DeepSeek 翻译
customer_response = chat(customer_messages)
print("客户邮件翻译结果:")
print(customer_response.content)
print("\n" + "-"*50 + "\n")

# 第二部分：服务回复翻译
service_reply = """Hey there customer, \
the warranty does not cover \
cleaning expenses for your kitchen \
because it's your fault that \
you misused your blender \
by forgetting to put the lid on before \
starting the blender. \
Tough luck! See ya!
"""

service_style_pirate = """a polite tone that speaks in English Pirate"""

# 格式化消息
service_messages = prompt_template.format_messages(
    style=service_style_pirate,
    text=service_reply
)

# 打印格式化后的提示
print("服务回复提示内容:")
print(service_messages[0].content)
print("\n" + "-"*50 + "\n")

# 调用 DeepSeek 翻译
service_response = chat(service_messages)
print("服务回复翻译结果:")
print(service_response.content)